<!DOCTYPE html>
<html data-ng-app="register">
<head lang="en">
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
<title>大象与猩猩 | 用户注册</title>
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
<meta name="renderer" content="webkit">
<meta http-equiv="Cache-Control" content="no-siteapp" />
<link rel="alternate icon" type="image/png" href="assets/i/favicon.png">
<link rel="stylesheet" href="assets/css/amazeui.min.css" />
<style>
.header {
	text-align: center;
}

.header h1 {
	font-size: 200%;
	color: #333;
	margin-top: 30px;
}

.header p {
	font-size: 14px;
}
</style>
</head>
<body ng-controller="RegisterController">
	<div class="header">
		<div class="am-g">
			<h1>大象与猩猩</h1>
		</div>
		<hr />
	</div>
	<div class="am-g">
		<div class="am-u-lg-6 am-u-md-10 am-u-sm-centered">
			<div class="am-u-sm-12">
				<form class="am-form" id="submitForm">
					<div class="am-g am-margin-top-xs">
						<div class="am-u-sm-12 am-u-md-6 am-form-group am-form-icon">
							<i class="am-icon-user am-padding-left-sm"></i><input type="tel" name="phone" id="phone" data-ng-model="enterprise.phone" maxlength="11" placeholder="请输入手机号" required="required" class="am-form-field am-input-sm" autofocus="autofocus">
						</div>
					</div>
					<div class="am-g am-margin-top-xs">
						<div class="am-u-sm-8 am-u-md-5 am-form-group am-form-icon">
							<input name="code" data-ng-model="msm" placeholder="请输入手机验证码" type="text" class="am-form-field am-input-sm">
						</div>
						<div class="am-u-sm-4 am-u-md-4 am-u-end" style="padding: 0%;">
							<button class="am-btn am-btn-primary am-btn-sm" onclick="sendCode()">获取验证码</button>
						</div>
					</div>

					<div class="am-g am-margin-top-xs">
						<div class="am-u-sm-12 am-u-md-6 am-form-group am-form-icon">
							<i class="am-icon-lock am-padding-left-sm"></i><input id="password1" class="am-form-field am-input-sm" name="password" placeholder="密码" type="password" onchange="checkPasswords()" required="required">
						</div>
					</div>

					<div class="am-g am-margin-top-xs">
						<div class="am-u-sm-12 am-u-md-6 am-form-group am-form-icon">
							<i class="am-icon-lock am-padding-left-sm"></i><input id="password2" class="am-form-field am-input-sm"  name="password2" placeholder="请再输入一次" type="password" onchange="checkPasswords()" required="required">
						</div>
					</div>

					<div class="am-g am-margin-top-sm">
						<div class="am-u-sm-12 am-u-md-6 am-u-end">
							<input id="verify" value="确定" id="send" class="am-btn am-btn-primary am-btn-block" type="submit">
						</div>
					</div>
				</form>
			</div>

			<hr>
			<p>© 2014-2016 dxyxx, Inc. 浙ICP备14017672号</p>
		</div>
	</div>
	<script src="../resources/js/zepto1.1.6.min.js"></script>
	<script type="text/javascript">
		function sendCode() {
			event.preventDefault();

			var phone = $("#phone").val();
			if (phone == "") {
				alert("请输入手机号！");
				return;
			}
			$.ajax({
				type : "POST",
				url : "../sms/send",
				data : $.param({
					"phone" : phone,
					"type" : "Register"
				}),
				dataType : "json",
				success : function(data) {

					if (data.code == 0) {
						alert(data.info);
					} else {

						/* 	$("#verify").attr("disabled", false);
							$("#send").attr("disabled", true); */
						alert(data.info);
					}
				},
				error : function(data) {
				}
			});
		}

		function checkPasswords() {
			var pass1 = document.getElementById("password1");
			var pass2 = document.getElementById("password2");

			if (pass1.value != pass2.value) {
				pass1.setCustomValidity("两次输入的密码不匹配");
			} else
				pass1.setCustomValidity("");
		}
		
		
		$("#submitForm").submit(function submitPWD() {
			event.preventDefault();
			
			$.ajax({
				type : "GET",
				url : "../encryption/transfer?plain="+$('#password1').val(),
				success : function(data) {
					if (data.code == 1) {
						$('#password1').val(data.object);
						$('#password2').val(data.object);
						
						$.ajax({
							type : "POST",
							url : "../sms/smsregister",
							data : $("#submitForm").serialize(),
							success : function(data) {
								console.log(data);
								if (data.code == 1) {
									alert("注册成功！");
									window.location.href = "wechat-login.html";
								} else {
									alert(data.info);
									// 失败 清空密码 
									$('#password1').val('');
									$('#password2').val('');
								}
							},
							error : function(data) {
							}
						});
					} else {
						alert(data.info);
					}
				},
				error : function(data) {
				}
			});
			
		});
	</script>
</body>
</html>